package cn.iocoder.yudao.module.pm.controller.app.thawrecords;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.pm.controller.app.thawrecords.vo.AppThawRecordsPageReqVO;
import cn.iocoder.yudao.module.pm.controller.app.thawrecords.vo.AppThawRecordsRespVO;
import cn.iocoder.yudao.module.pm.controller.app.thawrecords.vo.AppThawRecordsSaveReqVO;
import cn.iocoder.yudao.module.pm.service.thawrecords.ThawRecordsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 过程管理-解冻专项台账")
@RestController
@RequestMapping("pplan/pm/thaw-records")
@Validated
public class AppThawRecordsController {

    @Resource
    private ThawRecordsService thawRecordsService;

    @PostMapping("/create")
    @Operation(summary = "创建过程管理-解冻专项台账")
    @PreAuthorize("@ss.hasPermission('pm:thaw-records:create')")
    public CommonResult<Long> createThawRecords(@Valid @RequestBody AppThawRecordsSaveReqVO createReqVO) {
        return success(thawRecordsService.appCreateThawRecords(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新过程管理-解冻专项台账")
    public CommonResult<Boolean> updateThawRecords(@Valid @RequestBody AppThawRecordsSaveReqVO updateReqVO) {
        thawRecordsService.appUpdateThawRecords(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除过程管理-解冻专项台账")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('pm:thaw-records:delete')")
    public CommonResult<Boolean> deleteThawRecords(@RequestParam("id") Long id) {
        thawRecordsService.appDeleteThawRecords(id);
        return success(true);
    }


    @GetMapping("/get")
    @Operation(summary = "获得过程管理-解冻专项台账")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppThawRecordsRespVO> getThawRecords(@RequestParam("id") Long id) {
        AppThawRecordsRespVO thawRecords = thawRecordsService.appGetThawRecords(id);
        return success(thawRecords);
    }

    @GetMapping("/page")
    @Operation(summary = "获得过程管理-解冻专项台账分页")
    public CommonResult<PageResult<AppThawRecordsRespVO>> getThawRecordsPage(@Valid AppThawRecordsPageReqVO pageReqVO) {
        PageResult<AppThawRecordsRespVO> pageResult = thawRecordsService.appGetThawRecordsPage(pageReqVO);
        return success(pageResult);
    }



}